//导入 mongoose
const mongoose = require('mongoose');
//创建文档的结构对象
//设置集合中文档的属性以及属性值的类型
let testmodes = new mongoose.Schema({
  name: {
    type: String,
    required: true
  },
  phoneNumber: {
    type: String,
    required: true,
    validate: {
      // 简单的电话号码格式验证，可根据实际需求调整
      validator: function (v) {
        return /^\+?[1-9]\d{1,14}$/.test(v);
      },
      message: props => `${props.value} 不是有效的电话号码！`
    }
  },
  goods: {
    type: String,
    required: true,
    trim: true
  },
  machine_model: {
    type: String,
    required: true,
    trim: true
  },
  machine_failure: {
    type: String,
    required: true,
    trim: true
  },
  creation_time: {
    type: Date,
    default: Date.now // 默认值为当前时间
  }
});

//创建模型对象  对文档操作的封装对象
let testmode = mongoose.model('testmode', testmodes);

//暴露模型对象
module.exports = testmode;
